let id = 0
class Dep {
    constructor() {
        this.subs = []
        this.id = id++
    }
    depend() {
        // this.subs.push(Dep.target)
        if (Dep.target) {
            Dep.target.addDep(this)
        }
    }
    addSub(watcher) {
        this.subs.push(watcher)
    }
    notify() {
        this.subs.forEach((watcher => {
            watcher.updata()
        }))
    }
}

Dep.target = null
const targetStack = []
export function pushTarget(watcher) {
    Dep.target = watcher
    targetStack.push(watcher)
}

export function popTarget() {
    // Dep.target = null
    targetStack.pop()
    Dep.target = targetStack[targetStack.length - 1]
}

export default Dep